package cn.edu.cjw.APMFP.RoleRight.Service;

import java.util.ArrayList;

import cn.edu.cjw.APMFP.RoleRight.DAO.RoleRightDAO;
import cn.edu.cjw.APMFP.RoleRight.DAO.RrDAOImpl;
import cn.edu.cjw.APMFP.RoleRight.pojo.RoleRight;

public class RrServiceImpl implements RoleRightService {

	RoleRightDAO roleRightDAO = new RrDAOImpl();

	public boolean addRole(RoleRight r) throws Exception {

		boolean addRole = false;

		if (r.judge()) {

			if (roleRightDAO.SearchRoleByrNUM(r.getRNum()).judge()) {

				new Exception("角色或角色编号已存在！").printStackTrace();
				return addRole;

			} else {

				addRole = roleRightDAO.addAndUpdateRole(r);

			}

		} else {

			new Exception("角色编号、名称、描述、权限不为空！").printStackTrace();

		}

		return addRole;

	}

	public boolean removeRole(RoleRight r) throws Exception {

		return roleRightDAO.removeRole(r);

	}

	public boolean updateRoleRight(RoleRight r, ArrayList<String> list) throws Exception {

		r.setRRight(list);

		return roleRightDAO.addAndUpdateRole(r);
	}

	public boolean updateRoleDescribe(RoleRight r, String newDescribe) throws Exception {

		r.setRDescribe(newDescribe);

		return roleRightDAO.addAndUpdateRole(r);
	}

	public boolean updateRoleName(RoleRight r, String newName) throws Exception {

		r.setRName(newName);

		return roleRightDAO.addAndUpdateRole(r);
	}
	
	public boolean updateRole(RoleRight r, ArrayList<String> list, String newDescribe, String newName) throws Exception {
		r.setRRight(list);
		r.setRDescribe(newDescribe);
		r.setRName(newName);
		return roleRightDAO.addAndUpdateRole(r);
	}

	public RoleRight searchRoleByNum(String rNum) throws Exception {

		return roleRightDAO.SearchRoleByrNUM(rNum);
	}

	public ArrayList<RoleRight> searchRoleByName(String rName) throws Exception {

		return roleRightDAO.SearchRoleByName(rName);

	}

	public ArrayList<RoleRight> showAll() throws Exception {

		return roleRightDAO.showAll();

	}

	

}
